<template>
  <div class="wrapper">
    <div class="header">登录授权</div>
    <div class="img-wrap"
         w-750-426
         aspectratio>
      <img src="../../assets/images/accredit.png"
           alt=""
           aspectratio-content>
    </div>
    <div class="content">正在授权中...</div>
  </div>
</template>

<script>
import {
  Toast
} from 'vant'
import { isLogin } from '@/assets/js/isLogin'
export default {
  data () {
    return {
      sessid: ''
    }
  },
  methods: {
    postToken () {
      this.$api.login.loginSucc()
        .then(this.postTokenSucc)
        .catch((e) => {
          console.log(e)
        })
    },
    postTokenSucc (res) {
      const path = this.$localStorage.get('authUrl')
      res = res.data
      if (this.$api.CODE_OK === res.code && res.data) {
        this.$localStorage.set('loginStatus', res.msg)
        const data = res.data
        this.$localStorage.set('avatar', data.avatar)
        this.$localStorage.set('userName', data.nickname)
        this.$localStorage.set('vip', data.level)
        this.$localStorage.set('phone', data.mobile)
        let date = +new Date()
        this.$localStorage.set('loginDate', date)
        this.$router.replace(path)
      } else {
        Toast({
          message: res.msg,
          duration: 1000,
          forbidClick: true
        })
        this.$localStorage.remove('loginStatus')
        this.$localStorage.remove('loginDate')
        isLogin(path)
      }
    }
  },
  activated () {
    this.postToken()
  }
}

</script>
<style lang='stylus' scoped>
@import '~stylus/variable.styl'
@import '~stylus/mixins.styl'

.wrapper
  width 100%
  height 100%

.header
  width 100%
  height 88px
  background $common_bgc
  box-shadow 0px 0px 0px 0px rgba(5, 5, 5, 0.12)
  display flex
  justify-content center
  align-items center
  font-size $back_fz
  color $common_fz_color
  font-weight 500

.img-wrap
  margin-bottom 100px

.content
  font-size $back_fz
  color $common_fz_color
  display flex
  width 100%
  justify-content center
</style>
